package com.JJL.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class SSOUtil {

    private static final String USERNAME = "jjl";
    private static final String PASSWORD = "123456";

    /**
     * 简单的登陆验证
     * @param username
     * @param password
     * @return
     */
    public static boolean checkLogin(String username, String password) {
        if(USERNAME.equals(username) && PASSWORD.equals(password)){
            return true;
        }
        return false;
    }

    /**
     * 简单的cookie验证
     * @param request
     * @return
     */
    public static boolean checkCookie(HttpServletRequest request) {
        if(request.getCookies()!=null){
            //检查是否存在相应的登陆凭证
            for(Cookie cookie : request.getCookies()){
                if("SameDomSSO".equals(cookie.getName()) && "sso".equals(cookie.getValue())){
                    return true;
                }
            }

        }
        return false;
    }

}
